package semantic.rules.walk

import utils.data.CTree
import scala.collection.mutable.Buffer
import semantic.COperations._
import lexis.CLexemeType
import syntax.{CGrammar, CASTNode}
import syntax.CGrammar._
import semantic.rules.CRuleException

object CWalkRuleAddSubMulDiv extends CWalkRule
{
    override val categories = CAddSub :: CMulDiv :: Nil

    override def post(node:CASTNode)(implicit tree:CTree[CASTNode], code:Buffer[String]) = if (node.children.size > 1) node().secondChild().category.name match
    {
        case CLexemeType.ADD.name => code += ADD
        case CLexemeType.SUB.name => code += SUB
        case CLexemeType.MUL.name => code += MUL
        case CLexemeType.DIV.name => code += DIV
        case nm => CRuleException(CRuleException.WRONG_NODE_TYPE(nm))
    }
}
